package com.haifeng.jupiter.common.redis.handler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.Cache;
import org.springframework.cache.interceptor.SimpleCacheErrorHandler;

/**
 * <p>
 * 缓存失败处理器，缓存失败继续执行数据库查询
 * </p>
 *
 * @author: Haifeng
 * @date: 2020-08-09
 */
@Slf4j
public class RedisCacheErrorHandler extends SimpleCacheErrorHandler {

    @Override
    public void handleCacheGetError(RuntimeException exception, Cache cache, Object key) {
        log.error("【从redis中Get缓存[{}]失败】：", key, exception.getMessage());
    }

    @Override
    public void handleCachePutError(RuntimeException exception, Cache cache, Object key, Object value) {
        log.error("【从redis中Put缓存[{}]失败】：", key, exception.getMessage());
    }

    @Override
    public void handleCacheEvictError(RuntimeException exception, Cache cache, Object key) {
        log.error("【从redis中Evict缓存[{}]失败】：", key, exception.getMessage());
    }

    @Override
    public void handleCacheClearError(RuntimeException exception, Cache cache) {
        log.error("【从redis中Clear缓存失败】：", exception.getMessage());
    }
}
